<template>
  <div>
    <div class="title font14 ma30-15">
      <p>成员申请管理</p>
    </div>
    <div class="pa15 bor7 group">
      <!-- 内容 -->
      <div class="table-responsive">
        <table class="table">
          <tbody>
            <tr>
              <th>团队名称</th>
              <th>申请人</th>
              <th>手机号</th>
              <th>电子邮箱</th>
              <th>性别</th>
              <th>所在城市</th>
              <th>审核状态</th>
              <th>操作</th>
            </tr>
            <tr v-for="itemList in this.defaultList" :key="itemList.id">
               <td>{{ itemList.team.name | contentText}}</td>
               <td>{{ itemList.info_name }}</td>
               <td>{{ itemList.info_phone }}</td>
               <td>{{ itemList.info_email }}</td>
               <td v-if="itemList.info_sex == 1">男</td>
               <td v-else-if="itemList.info_sex == 2">女</td>
               <td v-else>-</td>
               <td>{{ itemList.info_city }}</td>
               <td style="color: rgb(64, 158, 255);" v-if="itemList.status == 0">审核中</td>
               <td style="color: rgb(108, 161, 43);" v-else-if="itemList.status == 1">通过</td>
               <td style="color:red" v-else>不通过</td>
              <td v-if="itemList.status == 0">
                <!--el-button slot="reference" type="primary" @click="YesTeamapply(''+itemList.id+'')">通过</el-button>
                <el-button slot="reference" type="primary" @click="NoTeamapply(''+itemList.id+'')">未通过</el-button-->

                <el-popover placement="top" width="200" trigger="click"
                            :ref="'popover-' + itemList.id"
                >
                  <p>通过成员申请？</p>
                  <div style="text-align: right; margin: 0">
                    <el-button
                      type="primary"
                      size="mini"
                      @click="YesTeamapply(''+itemList.id+'')"
                    >确定</el-button
                    >
                    <el-button
                      size="mini"
                      class="quxiao"
                      type="text"
                      @click="pCancel(itemList.id)"
                    >取消</el-button
                    >
                  </div>
                  <el-button slot="reference"  type="danger">通过</el-button>
                </el-popover>

                <el-popover placement="top" width="200" trigger="click"
                            :ref="'popovert-' + itemList.id"
                >
                  <p>不通过成员申请？</p>
                  <div style="text-align: right; margin: 0">
                    <el-button
                      type="primary"
                      size="mini"
                      @click="NoTeamapply(''+itemList.id+'')"
                    >确定</el-button
                    >
                    <el-button
                      size="mini"
                      class="quxiao"
                      type="text"
                      @click="pCancelt(itemList.id)"
                    >取消</el-button
                    >
                  </div>
                  <el-button slot="reference"  type="danger">未通过</el-button>
                </el-popover>
              </td>
              <td v-else>--</td>

            </tr>
          </tbody>
        </table>
      </div>
      <!-- 分页 -->
      <div class="block ta">
        <el-pagination
          layout="  prev, pager, next "
          :page-size="page_size"
          @current-change="current_change"
          :current-page.sync="currentPage"
          :pager-count="5"
          :total="info.total"
          v-if="info.pages > 1"
        >
        </el-pagination>
      <el-empty description="暂无数据" v-if="info.total == 0"></el-empty>
      </div>
    </div>
  </div>
</template>

<script>
import { formatDate } from "../../assets/data.js";
export default {
  // 时间戳
  filters: {
    formatDate(time) {
      time = time * 1000;
      let date = new Date(time);
      return formatDate(date, "yyyy-MM-dd hh:mm:ss");
    },
  },
  data() {
    return {
      isActive: 1,
      defaultList: [],
      info: [], //数据
      page_size: 8, //每页多少数据
      currentPage: 1, //默认当前页为第一页
      sort: '',
      keyword: "",
      visible1: false,
      visible2: false,
      visible3: false,
      visible4: false,
      visible5: false,
      visible6: false,
      visible7: false,
    };
  },
  mounted() {
    this.getAllList();
  },
  methods: {
    pCancel(id) {
      this.$refs[`popover-`+id][0].doClose()
    },
    pCancelt(id) {
      this.$refs[`popovert-`+id][0].doClose()
    },
    getAllList() {
      var that = this;
      this.$axios
        .get(
          this.$api +
          "//api/my/teamapplylist?team_id=&page_no="+that.currentPage+"&page_size="+that.page_size
        )
        .then(function (response) {
          that.defaultList = response.data.data.data;
          that.info = response.data.data;
          //console.log('List', that.defaultList);
        })
        .catch(function (error) {
          //console.log(error);
        });
    },
    //同意申请
    YesTeamapply(id) {
      //console.log(1231);
      //console.log(id);
      var that = this;
      this.$axios
        .get(this.$api + "//api/teamapply/yes?id=" + id)
        .then(function (response) {
          //that.defaultList = response.data.data.data;
          if (response.data.code == 1) {
            that.$message({
              message: response.data.msg,
              type: "success",
            });
            that.getAllList();
          } else {
            that.$message.error(response.data.msg);
          }
          //console.log(response.data);
        })
        .catch(function (error) {
          //console.log(error);
        });
    },
    //拒绝申请
    NoTeamapply(id) {
      //console.log(1231);
      //console.log(id);
      var that = this;
      this.$axios
        .get(this.$api + "//api/teamapply/no?id=" + id)
        .then(function (response) {
          //that.defaultList = response.data.data.data;
          if (response.data.code == 1) {
            that.$message({
              message: response.data.msg,
              type: "success",
            });
            that.getAllList();
          } else {
            that.$message.error(response.data.msg);
          }
          //console.log(response.data);
        })
        .catch(function (error) {
          //console.log(error);
        });
    },
    current_change(currentPage) {
      //改变当前页
      this.currentPage = currentPage;
      this.getAllList();
    },
    defaultSearch(){
      ////console.log(this.keyword);
      this.getAllList();
    }

  },
};
</script>

<style scoped>
html {
  height: 100% !important;
  overflow-y: hidden !important;
}
.table th {
  border-top: none;
  background: #f6f5f5;
  font-size: 0.875rem;
  color: #545556;
  line-height: 3.4375rem !important;
  text-align: center;
  font-size: 0.875rem;
}
table tr td {
  line-height: 3.4375rem !important;
  text-align: center;
  font-size: 0.875rem;
}
.el-button--info {
  border-radius: 0.25rem;
  background: #f6f5f5;
  border: 1px solid #f6f5f5;
  color: #545556;
}
.el-button {
  padding: 0.3125rem 0.625rem;
  font-size: 0.875rem;
}
.table > tbody > tr > td {
  border-top: 1px solid #f6f5f5;
}
.el-button + .el-button {
  margin-left: 0.25rem;
}
.el-button--success {
  background: #19a15f;
}
.el-radio {
  margin-right: 0.5rem;
}
.el-radio__label {
  font-size: 0.875rem;
  padding-left: 0.3125rem;
}
tr .free {
  color: #de5044;
}
.table tr img {
  width: 3.4375rem;
  object-fit: cover;
}
</style>
